package com.example.nick.bodyapplication.recycler

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.nick.bodyapplication.databinding.ActivityListBinding

class ListActivity : AppCompatActivity() {
    lateinit var viewBinding: ActivityListBinding
    private lateinit var adapter: GridAdapter
    val alarmArrays = Array(size = 9, init = { i -> i})

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewBinding = ActivityListBinding.inflate(layoutInflater)
        setContentView(viewBinding.root)
        initList()
    }

    private fun initList() {
        adapter = GridAdapter()
        adapter.data = alarmArrays.toMutableList()
        viewBinding.recyclerViewList.adapter = adapter
        adapter.setOnItemClickListener { adapter, view, position ->
            Log.i("list", "setOnItemClickListener position:$position")
            Toast.makeText(this, "click:$position", Toast.LENGTH_SHORT).show()
        }
        adapter.setOnItemChildClickListener { adapter, view, position ->
            Log.i("list", "setOnItemChildClickListener position:$position")
            Toast.makeText(this, "child click:$position", Toast.LENGTH_SHORT).show()
            adapter.notifyItemChanged(position)
        }
    }
}